import { defineStore } from 'pinia'

const wantStore = defineStore('wantPinia',{
    state: () => {
        return{
            userWantList:[]
        }
    },

    getters: {
        // 返回电影
        wantMoviesList: (state) => {
            return state.userWantList.filter(item => item.type === 0)
        },

        // 返回演出
        wantPlaysList: (state) => {
            return state.userWantList.filter(item => item.type === 1)
        }
    },

    actions: {
        addWantList(wantItem) {
            this.userWantList = [wantItem, ...this.userWantList.filter(i => i.id !== wantItem.id)]
        },
        delWantList(id:string) {
            this.userWantList = this.userWantList.filter(i => i.id !== id)
        },
    },

    // 使用该插件，开启数据缓存
    persist: {
        //这里存储默认使用的是session
        enabled: true,
        strategies: [
            {
                //key的名称
                key: 'my_want',
                //更改默认存储，我更改为localStorage
                storage: localStorage,
            }
        ]
    },
    
})
export {
    wantStore
}